<template>
  
  <div>
    <h4>当前是订单信息-- 订单信息refund</h4>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-col :span="3">
            <el-form-item>
                <el-input
                v-model="formInline.orderNumber"
                placeholder="订单编号"
                ></el-input>
            </el-form-item>
        </el-col>
        
    
      <el-form-item>
        <el-input
          v-model="formInline.number"
          placeholder="设备编号 或者 蓝牙编码 "
        ></el-input>
      </el-form-item>
      <el-form-item>
<!--        D:\apache-tomcat-log-8.5.64\apache-tomcat-8.5.70-->
         <el-select v-model="formInline.projectid" clearable filterable placeholder="请选择项目" >
          <el-option
            v-for="item in selectData"
            :key="item.projectid"
            :label="item.projectName"
            :value="item.projectid" />
        </el-select>
      </el-form-item>
     

      <el-form-item label="记录日期" label-width="160">
          <div class="block">
            <el-date-picker
              v-model="payTime"
              type="datetimerange"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="right"
            />
          </div>
        </el-form-item>
        
       <!-- <el-col :span="3">
            <el-form-item>
                <el-input
                v-model="formInline.address"
                placeholder="订单编号"
                ></el-input>
            </el-form-item>
        </el-col> -->
      <el-form-item>
        <el-select v-model="formInline.defarystatus" clearable filterable placeholder="支付类型">
          <el-option label="0，未支付" value="0"></el-option>
          <el-option label="1,支付失败" value="1"></el-option>
          <el-option label="2,支付成功" value="2"></el-option>
          <el-option label="3,退款中" value="3"></el-option>
          <el-option label="4,退款OK" value="4"></el-option>
          <el-option label="5,退款失败" value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" @click="dialogClaim = true">新增订单</el-button>
      </el-form-item>
        <el-form-item>
        <!-- <el-button type="success" @click="exportData" icon="el-icon-download">导出数据</el-button> -->
        <!-- // 添加导出按钮并声明导出方法 -->
        <!-- <el-button type="primary" >导入</el-button> -->

       </el-form-item>
        <el-form-item>
      <download-excel
             :data   = "tableData"
             :fields = "json_fields"
             type    = "csv"
             worksheet = "My Worksheet"
             name    = "订单信息.xls">
         <el-button type="success" icon="el-icon-download">VUE导出</el-button>

     </download-excel>

      </el-form-item>
        

    </el-form>
    
    <el-table :data="tableData" border style="width: 100%">
<!--    <el-table-column prop="orderNumber" label="订单号" width="220px"> </el-table-column> -->
        <el-table-column prop="orderNumber" label="订单号" width="220px">
        <template slot-scope="scope">
          <el-button @click="handleClickorderNumber(scope.row)" type="text" size="big">{{scope.row.orderNumber}}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="functionType" label="工作模式"> </el-table-column>
      <el-table-column prop="money" label="支付金额"> </el-table-column>
      <el-table-column prop="orderStatus" label="订单状态"> </el-table-column>
      <el-table-column prop="deletestate" label="逻辑删除"> </el-table-column>
      <el-table-column prop="number" label="编号">
        <template slot-scope="scope">
          <el-button @click="handleClicknumber(scope.row)" type="text" size="big">{{scope.row.number}}</el-button>
        </template>
      </el-table-column>
     
      <el-table-column prop="username" label="用户"> </el-table-column>
      <el-table-column prop="defary" label="支付状态"> </el-table-column>
      <el-table-column prop="defarytime" label="支付时间" width="180px"> </el-table-column>
      <el-table-column prop="defarytypes" label="支付渠道"></el-table-column>
      	<!-- <el-table-column
					prop="status"
					label="是否启用">
				<template slot-scope="scope">
					<el-tag size="small" v-if="scope.row.status === 1" type="success">已启用</el-tag>
					<el-tag size="small" v-else-if="scope.row.status === 0" type="danger">已禁用</el-tag>
				</template>

			</el-table-column> -->
      <el-table-column prop="projectName" label="项目"> 
         <template slot-scope="scope">
          <el-button @click="handleClickProject(scope.row)" type="text" size="big">{{scope.row.projectName}}</el-button>
     
        </template>
      </el-table-column>
      <el-table-column prop="address" label="投放位置"> </el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <!-- <el-button @click="handleClick(scope.row)" type="text" size="big">编辑项目</el-button> -->
          <template>
						<el-popconfirm title="这是一段内容确定删除吗？" @confirm="handleDelete(scope.row.orderid)">
							<el-button type="text" slot="reference">删除</el-button>
						</el-popconfirm>
					</template>
         
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[5,10, 15, 20, 30]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  
  <!--设备认领对话框-->
     <el-dialog
      title="提示"
      :visible.sync="dialogClaim"
      width="600px"
      :before-close="handleClaim"
    >
   
  

  <div>
<el-steps :active="active" finish-status="success">
  <el-step title="步骤 1"></el-step>
  <el-step title="步骤 2"></el-step>
  <el-step title="步骤 3"></el-step>
</el-steps>

<!-- <Step1 v-show="active==1"/> -->
<div :visible.sync="dialog">
    <h4>当前是订单管理-- 订单基本信息  acvite1</h4>
     <el-form :inline="true" :model="active1Math" class="demo-form-inline">
        <el-col :span="10">
            <el-form-item>
                <el-input
                v-model="active1Math.Number"
                placeholder="设备编号"
                ></el-input>
            </el-form-item>
        </el-col>
    
      <!-- <el-form-item>
        <el-input
          v-model="formInline.number"
          placeholder="设备编号 或者 蓝牙编码 "
        ></el-input>
      </el-form-item> -->        

       <el-form-item>
        <el-button type="primary" >扫码</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmitActive">查询</el-button>
      </el-form-item>

    </el-form>
    <div>
  
     <!-- <el-table
    ref="multipleTable"
    :data="tableData3"
    tooltip-effect="dark"
    style="width: 100%"
    @selection-change="handleSelectionChange"> -->
    <el-table :data="Activetable" tooltip-effect="dark" ref="currentRow"  style="width: 100%"   highlight-current-row  @current-change="handleSelectionChange" >
      <el-table-column
      type="index"
      width="55">
    </el-table-column>
        <el-table-column prop="functionType" label="洗衣类型"> </el-table-column>
      <el-table-column prop="money" label="价格（元）"> </el-table-column>
       <el-table-column prop="functionTime" label="时间/min" > </el-table-column>
      <el-table-column prop="describes" label="描述" width="220px"> </el-table-column>
    </el-table>
   

  
  
  </div>
  
  </div>
        <el-button type="success" @click="PlaceOrder" icon="el-icon-download">下单</el-button>
    
<!-- <el-button @click="prev" >上一步</el-button>
<el-button style="margin-top: 12px;" @click="next">下一步</el-button> -->
  </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm1()">取 消</el-button>
        <!-- <el-button type="primary" @click="ClaimForm()"
          >确 定</el-button
        > -->
      </div>
    </el-dialog>
  </div>
</template>

<script>

// 导入excel公共导出方法
import { exportExcel } from '@/api/common'


export default {
  name: "admin",
  data() {
    return {
      dialog: false,
      dialogClaim: false,
      active: 1,
      ActiveBaseid: "",
      Activetable: [],
      tableData: [],
      payTime: [], // 收入日期
      payTime1: null, // 收入日期1
      payTime2: null, // 收入日期2
      active1Math: {
        Number: "",
      },

      formInline: {
        user: "",
        region: "",
      },
      total: 0,
      size: 10,
      current: 1,
      currentRow: [],
      userInfo: {},

      /// 直接使用vue导出信息
       json_fields: {
            '订单号':'orderNumber',
            '编号':'number',
            '产品类型':'',
            '项目':'projectName',
            '位置':'address',
            '金额':'money',
            '工作模式':'functionType',
            '支付方式':'defarytypes',
            '支付时间':'defarytime',
            '用户':'username',
            // 'Complete name': 'name',
            // 'City': 'city',
            // 'Telephone': 'phone.mobile',
            // 'Telephone 2' : {
            //     field: 'phone.landline',
            //     callback: (value) => {
            //         return `Landline Phone - ${value}`;
            //     }
            // },
        },
        json_data: [
            {
                'name': 'Tony Peña',
                'city': 'New York',
                'country': 'United States',
                'birthdate': '1978-03-15',
                'phone': {
                    'mobile': '1-541-754-3010',
                    'landline': '(541) 754-3010'
                }
            },
            {
                'name': 'Thessaloniki',
                'city': 'Athens',
                'country': 'Greece',
                'birthdate': '1987-11-23',
                'phone': {
                    'mobile': '+1 855 275 5071',
                    'landline': '(2741) 2621-244'
                }
            }
        ],


    };
  },

  created() {
    this.selectDataMethod();
    this.getOrderList();
  },
  methods: {
    
    handleSelectionChange(val) {
      console.log(val);

      this.currentRow = val;
    },
    setCurrent() {
      console.info(this.currentRow);
      //this.$refs.singleTable.setCurrentRow(row);
    },

    //依据ID 查询到对应的 洗衣类型信息
    onSubmitActive() {
      this.$axios
        .get("/tFacilityBase/list", {
          params: {
            page: 0,
            limit: 10,
            type: null,
            model: null,
            math: this.active1Math.Number,
            projectid: null,
            address: null,
          },
        })
        .then((res) => {
          console.log(res);

          if (res.data.count > 0) {
            this.ActiveBaseid = res.data.data[0].id;
            this.$message({
              showClose: true,
              message: "恭喜你",
              type: "success",
            });
            this.active = 2;
            this.$axios
              .get("/tFacilityFunction/getinfo/" + this.ActiveBaseid)
              .then((res) => {
                console.log(res);
                this.Activetable = res.data.data;
              });
          } else {
            this.$message({
              showClose: true,
              message: "没有找到设备信息！！",
              type: "warning",
            });
          }
        });
    },
    ///  下单
    PlaceOrder() {
      // 获取到当前登录客户的一个ID
      this.$axios.get("/sys/userInfo").then((res) => {
        console.log(res)
       this.userInfo = res.data.data;
       
      console.log(this.userInfo);
      console.log(this.currentRow.functionid);
      console.log(this.currentRow.baseid);
      if (
        this.userInfo != "" &&
        this.currentRow.baseid!="" &&
        this.currentRow.functionid!="") {
        this.$axios
          .get("/tPayOrder/PlaceOrder", {
            params: {
              userInfoid: res.data.data.id,
              baseid: this.currentRow.baseid,
              functionid: this.currentRow.functionid,
            },
          })
          .then((res) => {
           this.$message({
              showClose: true,
              message: "恭喜你",
              type: "success",
            });
             this.active = 3;
             this.getOrderList();
            this.handleClaim()
          });
      } else {
        alert("请选择你需要的下单的信息");
      }
      });
    },
 /// 逻辑删除订单信息
    handleDelete(id){
        this.$axios.get("/tPayOrder/delete/"+id).then(res => {
                  this.$message({
                    showClose: true,
                    message: '恭喜你，删除操作成功',
                    type: 'success',
                    onClose:() => {
                     this.getOrderList();
                    }
                  });
                })
    },
    handleSizeChange(val) {
      console.log(`每页条` + val);
      this.size = val;
      this.getOrderList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ` + val);
      this.current = val;
      this.getOrderList();
    },
    // 用户信息编辑的一个取消
    resetForm() {
      this.dialogClaim = false;
      this.editForm = {};
      this.active = 0;
    },
    resetForm1() {
      this.active = 1;
      this.dialogClaim = false;
    },
    // 关闭用户信息框
    // handleClose() {
    //   this.resetForm();
    // },
    handleClaim() {
      this.resetForm1();
    },
    // 查询全部的项目信息
    selectDataMethod() {
      this.$axios.get("/sys/userInfo").then(resOne => {
					
					this.userInfo = resOne.data.data
         // console.log("--------------------")
         // console.log(resOne.data.data);
          if(resOne.data.data.Projecttrue){
              this.$axios
              .get("/tProjectBase/list", {
                params: {
                  current: 0,
                  size: 0,
                },
              })
              .then((res) => {
                console.log(res.data.data);
                this.selectData = res.data.data;
              });
          }
          else{
             this.selectData = [{
               "projectid":resOne.data.data.projectid,
               "projectName":resOne.data.data.projectname
             }];
             this.formInline.projectid=resOne.data.data.projectid;
          
          }
           this.getOrderList();
				})
     
    },
    //  条件查询设备信息

    getOrderList() {
      console.log(this.formInline);
      console.log(this.payTime);
      this.formInline.dateup=this.payTime[0];
      this.formInline.datedown=this.payTime[1];
      this.$axios
        .get("/tPayOrder/list", {
          params: {
            page: this.current,
            limit: this.size,
            orderNumber: this.formInline.orderNumber,
            number: this.formInline.number,
            date1: this.payTime[0],
            date2: this.payTime[1],
            projectid: this.formInline.projectid,
            defarystatus: this.formInline.defarystatus,
          },
        })
        .then((res) => {
          console.log(res);
          this.tableData = res.data.data;

          this.total = res.data.count;
        });
    },
    // 调用导出方法
    exportData(){
      //exportExcel(this.formInline,'/tPayOrder/export','用户信息.xlsx')
     //exportExcel('/download','用户信息.xlsx')
     
		//  console.log("wo_id = "+wo_id);
		 // const url = this.BASE_API_URL + 'springbootApi/downloadExcel?wo_id='+wo_id;
		 window.localhost= this.$axios.get("/download", 
		  	{
		  		responseType: 'blob'       
		  	},{
      
        })
		  .then((res) => {
		    if (!res) return
		
		    console.log("res data = "+res.data);
		    let blob = new Blob([res.data], {type: 'application/vnd.ms-excel;charset=utf-8'}) // 文件类型
		    console.log(res.headers['content-disposition']); // 从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx") 设置的文件名;
		    //以=分割取数组[1]元素为文件名
		    let filename = window.decodeURI(res.headers['content-disposition'].split('=')[1])
		    let url = window.URL.createObjectURL(blob);  // 创建下载链接
		    let aLink = document.createElement("a");    // 赋值给a标签的href属性
		    aLink.style.display = "none";
		    aLink.href = url;
		    aLink.setAttribute("download", filename);
		    document.body.appendChild(aLink);   // 将a标签挂载上去
		    aLink.click();          // a标签click事件
		    document.body.removeChild(aLink);  // 移除a标签
		    window.URL.revokeObjectURL(url);   // 销毁下载链接
		
		    return this.$message.success("导出报关单成功");
		  }).catch(function (error) {
		    console.log(error);
		  })


    },

    //  点击搜索按钮
    onSubmit() {
      console.log("submit!");
      this.getOrderList();
    },

  /// 点击订单到一个订单详情
  handleClickorderNumber(row){
    console.log(row)
      this.$router.push({ path: "/order/OrderBase/" + row.orderNumber });
  },

    ///  点击设备编号，到一个具体的设备信息页面
    handleClicknumber(row) {
      this.$router.push({ path: "/facility/FacilityBase/" + row.number });
      console.log(row);
    },
    //点击一个项目名称，到一个具体的项目信息的页面
    handleClickProject(row) {
      this.$router.push({ path: "/sys/ProjectBser/" + row.projectid });
      console.log(row);
    },
  },
};
</script>

<style scoped>
/*步骤条的高度*/
.box3 >>> .el-step.is-vertical {
  height: 50%;
}
</style>